function JCTreeSelectControl(arParams){var _this=this;this.arParams=arParams;this.arTreeData={};this.multiple=this.arParams.MULTIPLE;if(null!=arParams.VALUE)this.SetValue(arParams.VALUE);this.div=null;this._onkeypress=function(e){if(null==e)e=window.event;if(null==e)return;if(e.keyCode==27)_this.CloseDialog()};var current_value=[];this.getElementsByName=function(e,t){var s=[];var i=document.getElementsByTagName(e);for(var r=0;r<i.length;r++){if(i[r].getAttribute("name")==t)s.push(i[r])}return s};this.SetValueFromInput=function(e){var t=[];var s=document.getElementById(e);if(s){t[t.length]=s.value}else{var i=this.getElementsByName("INPUT",e);if(i&&i.length>0){for(var r=0;r<i.length;r++)t[t.length]=i[r].value}else{i=this.getElementsByName("INPUT",e+"[]");if(i&&i.length>0){for(r=0;r<i.length;r++)t[t.length]=i[r].value}}}this.SetValue(t)};this.SetValue=function(e){if(typeof e=="string"||typeof e=="object"&&e.constructor==String)e=e.split(",");if(typeof e=="object"){current_value=[];for(var t=0;t<e.length;t++){var s=parseInt(e[t]);if(!isNaN(s))current_value[current_value.length]=s}}return typeof current_value=="object"};this.GetValue=function(e){if(null==e)e=false;if(e){if(null!=current_value)return current_value.join(",")}return current_value};this._control=null;this._timerId=null;this._delay=500;this._value="";this._result=[];this._ajax_error="";this._div=null;this._search_focus=-1;this.InitControl=function(e){this._control=document.getElementById(e);if(this._control){this._control.value=_this.arParams.START_TEXT;this._control.value_tmp=this._control.value;this._control.className="bx-search-control-empty";this._control.onfocus=this.__control_focus;this._control.onblur=this.__control_blur;this._control.onkeydown=this.__control_keypress}};this.Run=function(){if(null!=_this._timerId)clearTimeout(_this._timerId);_this._search_focus=-1;if(_this._control.value&&_this._control.value!=_this._control.value_tmp){_this._value=_this._control.value;var e=_this.arParams.AJAX_PAGE+"?MODE=search&win_id="+_this.arParams.WIN.id+"&search="+encodeURIComponent(_this._value);if(_this.arParams.AJAX_PARAMS){for(var t in _this.arParams.AJAX_PARAMS)e+="&"+t+"="+encodeURIComponent(_this.arParams.AJAX_PARAMS[t])}BX.ajax.get(e,_this.SetResult)}};this.SetResult=function(data){var DATA=[];_this._ajax_error="";if(data.length>0){if(data.substr(0,1)=="[")eval("DATA = "+data);else _this._ajax_error=data}_this._result=DATA;_this.SearchShow()};this.SearchShow=function(){if(null==_this._div){var e=BX("_f_popup_content");e.style.position="relative";var t=BX.pos(_this._control,true);_this._div=e.insertBefore(document.createElement("DIV"),e.firstChild);_this._div.className="mts-search-result";_this._div.style.top=t.bottom+"px";_this._div.style.left="0px";_this._div.style.zIndex=111e3;jsUtils.addCustomEvent("onTreeSearchClose",_this.__onclose,[],_this)}else{_this._div.innerHTML=""}if(_this._result.length>0){for(var s=0;s<_this._result.length;s++){_this._result[s]._row=_this._div.appendChild(document.createElement("DIV"));_this._result[s]._row.className="mts-search-result-row";_this._result[s]._row.innerHTML=_this._result[s].NAME;_this._result[s]._row.onclick=_this.__result_row_click;_this._result[s]._row.__bx_data=_this._result[s]}}else{if(_this._ajax_error.length>0)_this._div.innerHTML="<i>"+_this._ajax_error+"</i>";else _this._div.innerHTML="<i>"+_this.arParams["NO_SEARCH_RESULT_TEXT"]+"</i>"}_this._div.style.display="block"};this._openSection=function(e,t){if(null==t)t=false;var s=document.getElementById("mts_section_"+e);if(null!=s){var i=s.parentNode;if(null!=i){i=i.previousSibling;if(null!=i&&i.id&&i.id.substr(0,20)=="mts_section_"){_this._openSection(parseInt(i.id.substr(20)))}}_this.LoadSection(e,true,t)}};this.__result_row_click=function(){_this._openSection(this.__bx_data.SECTION_ID,true);var e=document.getElementById("mts_"+this.__bx_data.ID);if(null!=e){if(e.className!="mts-row mts-selected"){e.onclick()}}else{if(_this.multiple)current_selected[current_selected.length]=parseInt(this.__bx_data.ID);else current_selected[0]=parseInt(this.__bx_data.ID)}};this.__onclose=function(){if(null!=_this._div)_this._div.parentNode.removeChild(_this._div);if(null!=_this._timerId)clearTimeout(_this._timerId);jsUtils.removeCustomEvent("onTreeSearchClose",_this.__onclose)};this.__control_keypress=function(e){if(null==e)e=window.event;switch(e.keyCode){case 13:if(_this._search_focus<0)_this.Run();else{_this._control.onblur();_this._control.blur();_this._result[_this._search_focus]._row.onclick()}break;case 40:if(_this._result.length>0&&_this._search_focus<_this._result.length-1){if(_this._search_focus>=0)_this._result[_this._search_focus]._row.className="mts-search-result-row";_this._search_focus++;_this._result[_this._search_focus]._row.className="mts-search-result-row mts-search-result-row-selected"}break;case 38:if(_this._result.length>0&&_this._search_focus>-1){_this._result[_this._search_focus]._row.className="mts-search-result-row";_this._search_focus--;if(_this._search_focus>=0)_this._result[_this._search_focus]._row.className="mts-search-result-row mts-search-result-row-selected"}break;default:if(null!=_this._timerId)clearTimeout(_this._timerId);_this._timerId=setTimeout(_this.Run,_this._delay);break}};this.__control_focus=function(){if(this.value==this.value_tmp){this.value="";this.className=""}if(null!=this._div)this._div.style.display="block"};this.__control_blur=function(){if(_this.value==""){_this.value=_this.value_tmp;_this.className="bx-search-control-empty"}if(null!=_this._div){setTimeout(function(){_this._div.style.display="none"},300)}};this.OnSelect=function(){if(null!=this.arParams.ONSELECT){var e=this.GetValue();if(this.arParams.GET_FULL_INFO){var t=[];for(var s=0;s<e.length;s++){t[t.length]=this.arTreeData[e[s]]}e=t;this.arParams.ONSELECT(e)}else{this.arParams.ONSELECT(e)}}};this.Show=function(e){if(null!=this.div)return;var t=this;if(null==e)e={};if(null==e.id)e.id="tree_selector_select_control";if(null==e.className)e.className="";this.arParams.WIN=e;CHttpRequest.Action=function(e){t._ShowWindow(e)};var s=this.arParams.AJAX_PAGE+"?win_id="+this.arParams.WIN.id;if(this.arParams.AJAX_PARAMS){for(var i in this.arParams.AJAX_PARAMS)s+="&"+i+"="+encodeURIComponent(this.arParams.AJAX_PARAMS[i])}if(this.arParams.INPUT_NAME)this.SetValueFromInput(this.arParams.INPUT_NAME);var r=this.GetValue(true);if((this.multiple?r.length:r)>0)s+="&value="+r;if(this.multiple)s+="&multiple=Y";ShowWaitWindow();CHttpRequest.Send(s)};this._ShowWindow=function(e){CloseWaitWindow();var t=this;this.div=document.body.appendChild(document.createElement("DIV"));this.div.id=this.arParams.WIN.id;this.div.className="settings-float-form"+(this.arParams.WIN&&this.arParams.WIN.className?" "+this.arParams.WIN.className:"");this.div.style.position="absolute";this.div.style.zIndex="110000";this.div.innerHTML=e;this.div.__object=this;var s=BX.GetWindowSize();var i=parseInt(s.scrollLeft+s.innerWidth/2-this.div.offsetWidth/2);var r=parseInt(s.scrollTop+s.innerHeight/2-this.div.offsetHeight/2);jsFloatDiv.Show(this.div,i,r);jsUtils.onCustomEvent("onTreeSearchShow",{div:this.div});jsUtils.onCustomEvent("onTreeSearchShow",{div:this.div});BX.bind(document,"keypress",this._onkeypress)};this.CloseDialog=function(){BX.unbind(document,"keypress",this._onkeypress);jsUtils.onCustomEvent("onTreeSearchClose",{div:this.div});this._div=null;jsFloatDiv.Close(this.div);this.div.parentNode.removeChild(this.div);this.div=null};this.LoadSection=function(e,t,s){if(null==t)t=false;if(null==s)s=false;e=parseInt(e);var i=document.getElementById("mts_section_"+e);if(null==i.BX_LOADED){var r=this.arParams.AJAX_PAGE+"?MODE=section&win_id="+this.arParams.WIN.id+"&SECTION_ID="+e;if(this.arParams.AJAX_PARAMS){for(var l in this.arParams.AJAX_PARAMS)r+="&"+l+"="+encodeURIComponent(this.arParams.AJAX_PARAMS[l])}if(s){BX.ajax.get(r,function(t){_this.ShowSection(t);document.getElementById("mts_search_layout").scrollTop=document.getElementById("mts_section_"+e).offsetTop-40})}else{BX.ajax.get(r,this.ShowSection)}}else if(s){document.getElementById("mts_search_layout").scrollTop=document.getElementById("mts_section_"+e).offsetTop-40}var a=document.getElementById("bx_children_"+e);if(t||a.style.display=="none"){i.firstChild.className=i.firstChild.className.replace("mts-closed","mts-opened");a.style.display="block"}else{i.firstChild.className=i.firstChild.className.replace("mts-opened","mts-closed");a.style.display="none"}};this.ElementSet=function(){if(!!this.arParams.SET_ALWAYS||current_selected.length>0){this.SetValue(current_selected);this.OnSelect()}this.CloseDialog()};this.ElementSelect=function(){if(_this.multiple){var e=false;for(var t=0;t<current_selected.length;t++){if(current_selected[t]==this.BX_ID){e=true;break}}if(e){this.className="mts-row";current_selected=current_selected.slice(0,t).concat(current_selected.slice(t+1));this.firstChild.checked=false}else{current_selected[current_selected.length]=this.BX_ID;this.className="mts-row mts-selected";this.firstChild.checked=true}}else{for(t=0;t<current_selected.length;t++){var s=document.getElementById("mts_"+current_selected[t]);if(s){s.className="mts-row";s.firstChild.checked=false}}current_selected=[this.BX_ID];this.className="mts-row mts-selected";this.firstChild.checked=true}};this.ShowSection=function(data){var DATA=[];if(data.length>0)eval("DATA = "+data);var SECTION_ID=DATA.SECTION_ID;var arElements=DATA.arElements;var obSection=document.getElementById("mts_section_"+SECTION_ID);if(!obSection.BX_LOADED){obSection.BX_LOADED=true;var obSectionDiv=document.getElementById("mts_elements_"+SECTION_ID);if(obSectionDiv){obSectionDiv.innerHTML="";for(var i=0;i<arElements.length;i++){_this.arTreeData[arElements[i].ID]={ID:arElements[i].ID,NAME:arElements[i].NAME};var obUserRow=document.createElement("DIV");obUserRow.id="mts_"+arElements[i].ID;obUserRow.className="mts-row";obUserRow.BX_ID=arElements[i].ID;if(_this.multiple){var obCheckbox=document.createElement("INPUT");obCheckbox.type="checkbox";obCheckbox.id="mts_check_"+arElements[i].ID;obCheckbox.defaultChecked=false;for(var j=0;j<current_selected.length;j++){if(obUserRow.BX_ID==current_selected[j]){obCheckbox.defaultChecked=true;obUserRow.className+=" mts-selected";break}}}else{for(j=0;j<current_selected.length;j++){if(obUserRow.BX_ID==current_selected[j]){obUserRow.className+=" mts-selected";break}}obUserRow.ondblclick=function(){_this.ElementSet()}}obUserRow.onclick=_this.ElementSelect;obUserRow.innerHTML=arElements[i].CONTENT;if(_this.multiple){obUserRow.insertBefore(obCheckbox,obUserRow.firstChild)}obSectionDiv.appendChild(obUserRow)}var obClearer=obSectionDiv.appendChild(document.createElement("DIV"));obClearer.style.clear="both"}}}}
//# sourceMappingURL=script.map.js